package btree4j.template;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class TemplateDataRow implements Serializable {
    private static final long serialVersionUID = 1L;

    private Map<String, Object> data = new HashMap<>();

    public TemplateDataRow() {
    }

    public TemplateDataRow(Template template) {
        for (Column column : template.getColumns()) {
            data.put(column.getName(), null);
        }
    }

    public void setColumnValue(String columnName, Object value) {
        data.put(columnName, value);
    }

    public Object getColumnValue(String columnName) {
        return data.get(columnName);
    }

    public Map<String, Object> getData() {
        return data;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("TemplateDataRow [");
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            sb.append(entry.getKey()).append("=").append(entry.getValue()).append(", ");
        }
        if (sb.length() > 16) {
            sb.setLength(sb.length() - 2);
        }
        sb.append("]");
        return sb.toString();
    }
}